package com.edu.exam.enums.grading;

/**
 * 缓存生命周期策略枚举
 */
public enum CacheLifecyclePolicy {
    FIXED_TIME("FIXED_TIME", "固定时间过期"),
    LRU("LRU", "最近最少使用"),
    LFU("LFU", "最少使用频率"),
    FIFO("FIFO", "先进先出"),
    MANUAL("MANUAL", "手动清理"),
    NEVER_EXPIRE("NEVER_EXPIRE", "永不过期");

    private final String code;
    private final String description;

    CacheLifecyclePolicy(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static CacheLifecyclePolicy fromCode(String code) {
        for (CacheLifecyclePolicy policy : values()) {
            if (policy.getCode().equals(code)) {
                return policy;
            }
        }
        throw new IllegalArgumentException("Unknown cache lifecycle policy code: " + code);
    }

    @Override
    public String toString() {
        return description;
    }
}